from collections import deque

n, k = map(int, input().split())
Map = [list(input().strip()) for _ in range(n)]
dir = [(-1, 0), (0, -1), (1, 0), (0, 1)]

def check(x, y, fat):  # 检查胖度、障碍
    for i in range(x - fat, x + fat + 1):
        for j in range(y - fat, y + fat + 1):
            if i < 0 or i >= n or j < 0 or j >= n:
                return False
            if Map[i][j] == '*':
                return False
    return True

def bfs():
    vis = [[[0] * 3 for _ in range(n)] for _ in range(n)]
    vis[2][2][2] = 1
    q = deque()
    q.append((2, 2, 0, 2))  # 分别代表起点横纵坐标、步数、肥胖程度
    while q:
        x, y, step, fat = q.popleft()
        # 分别在k和2k时减肥
        if step >= 2 * k:
            fat = 0
        elif step >= k:
            fat = 1

        for i, j in dir:
            nx, ny = x + i, y + j
            if check(nx, ny, fat) and vis[nx][ny][fat] == 0:
                if nx == n - 3 and ny == n - 3:
                    return step + 1
                q.append((nx, ny, step + 1, fat))
                vis[nx][ny][fat] = 1
        if fat != 0:
            q.append((x, y, step + 1, fat))
    return -1

print(bfs())